﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;

namespace Super_Pong
{
    class Controller
    {
        //Lucas: Não há necessidade disso ainda! Vamos remover
        //e deixar controles estáticos mesmo! Vou fazer isso em uma outra
        //classe e depois remover essa
        String name = "default_controler";
        public enum State { RELEASED, PRESSED, WAITING_FOR_RELEASE }
        public enum Behavior { NORMAL, DETECT_INITIAL_PRESS_ONLY }
        public int amount = 0;
        private Behavior behavior;
        private State state;

        //Construtores - Lucas
        public Controller(String nm, Behavior bh)
        {
            name = nm;
            behavior = bh;
        }
        public Controller(String nm)
        {
            name = nm;
            behavior = Behavior.NORMAL;
        }

        //Corpo - Lucas
        public String getName()
        {
            return name;
        }

        public void reset()
        {
            state = State.RELEASED;
            amount = 0;
        }

        public void tap(){
		    press();
		    release();
	    }
	
	    public void press(){
		    press(1);
	    }

        public void press(int amount){
		   if(state != State.WAITING_FOR_RELEASE){
			    this.amount += amount;
			    state = State.PRESSED;
		    }
        }

        public void release(){
		    state = State.RELEASED;
	    }
	
	    public bool isPressed(){
		    return (getAmount() != 0);
	    }
	
	    public int getAmount(){
		    int retVal = amount;
		    if(retVal != 0){
			    if(state == State.RELEASED){
				    amount = 0;
			    }else if(behavior == Behavior.DETECT_INITIAL_PRESS_ONLY){
				    state = State.WAITING_FOR_RELEASE;
				    amount = 0;
			    }
		    }
		    return retVal;
	    }

	}
}
